<?php
namespace app\admin\controller;

use think\Controller;

class Admin extends Base
{
    public function add()
    {
    	if (request()->isPost()) {
    		// dump(input("post."));
    		// halt(input("post."));=>等同于dump();exit();
    		$data = input("post.");
    		//validate
    		$validate = validate('AdminUser');
    		if (!$validate->check($data)) {
                $this->error($validate->getError());
            }
            $data['password']=md5($data['password'].'_#tao_tp');
            $data['status'] = 1;

            //1 exception
            //2 add id
            try {
               $id = model('AdminUser')->add($data);
            } catch (\Exception $e) {
                $this->error($e->getMessage());
            }

            if ($id) {
                $this->success("id=".$id);
            }else{
                $this->error("errot");
            }

        }else{
            return $this->fetch();
        }

    }

    public function welcome()
    {
        return $this->fetch();
    }
}
